package com.kfm.am;

import java.util.Vector;

public class StringSortTest {

    public static void main(String[] args) {
        Vector vector = new Vector();
        vector.add("zyj");
        vector.add("lgw");
        vector.add("wt");
        vector.add("wj");
        vector.add("jwx");
        vector.add("wjheng");
        for (Object object : vector) {
            System.out.println(object);
        }
        System.out.println("排序后");
        sort(vector);
        for (Object object : vector) {
            System.out.println(object);
        }

    }

    public static void sort(Vector vector) {
        // compareTo(String str)
        int size = vector.size();
        for (int i = 0; i < size; i ++) {
            for (int j = 0; j < size - 1; j ++) {
                String str1 = (String)vector.get(j);
                String str2 = (String)vector.get(j + 1);
                if (str1.compareTo(str2) > 0) {
                    vector.set(j, str2);
                    vector.set(j + 1, str1);
                }
            }
        }
    }
}
